import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:thingskit/Pages/FastSetting/fastSettingPage.dart';
import 'package:thingskit/Pages/Home/homePage.dart';
import 'package:thingskit/Pages/My/MyPage.dart';

class NavigationController extends GetxController {
  var currentIndex = 0.obs;
  var currentLabel = '首页'.obs;

  final List<Widget> pages = [HomePage(), FastSettingPage(), MyPage()];
  final List<String> labels = ['首页', '设备速调', '我的'];
  final List<BottomNavigationBarItem> items = [
    BottomNavigationBarItem(icon: Icon(Icons.home), label: '首页'),
    BottomNavigationBarItem(icon: Icon(Icons.speed), label: '设备速调'),
    BottomNavigationBarItem(icon: Icon(Icons.person), label: '我的'),
  ];
}

class NavigationPage extends StatelessWidget {
  final NavigationController controller = Get.put(NavigationController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        centerTitle: true,
        backgroundColor: Colors.white,
        elevation: 0,
        title: Obx(
          () => Text(controller.labels[controller.currentIndex.value]),
        ),
      ),
      body: Obx(() => controller.pages[controller.currentIndex.value]),
      bottomNavigationBar: Theme(
        //去掉水波纹效果， 如果不需要，可以把Theme去掉
        data: ThemeData(splashColor: Colors.transparent),
        child: Obx(
          () => BottomNavigationBar(
            type: BottomNavigationBarType.fixed,
            backgroundColor: Colors.white,
            items: controller.items,
            selectedItemColor: Colors.blue,
            currentIndex: controller.currentIndex.value,
            onTap: (index) {
              controller.currentIndex.value = index;
            },

          ),
        ),
      ),
    );
  }
}
